package org.supda.system.controller.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.supda.system.util.SpringUtils;

/**
 * 定时任务
 * @author supda
 * @Date 2017-2-27 下午3:58:34
 *
 * Spring @Scheduled是Spring计划任务的一种很简洁的实现。用来替代Quartz的方案。
 */
//@Service
//@Lazy(false) 
public class ScheduledTasks{

/*	
	 @Scheduled(cron="0/5 * *  * * ? ")   //每5秒执行一次  
     @Override  
     public void myTest(){  
         
     }  */
		static boolean isFirst = true;
	 
	   // @Scheduled(cron="0/5 * *  * * ? ")   //每5秒执行一次   
	    public void trigger() {
	    	  System.out.println("进入测试"+System.currentTimeMillis());  
	    	
	    	  if(simpMessageSendingOperations != null)
	    		simpMessageSendingOperations.convertAndSend("/topic/actual", new Greeting(System.currentTimeMillis()+" "));
	    }
	    
	    
		//此处无法使用注解,BUG？
		public  static SimpMessageSendingOperations simpMessageSendingOperations;
		
		//@Autowired private SimpMessageSendingOperations simpMessageSendingOperations;

/*	    public static SimpMessageSendingOperations getSimpMessageSendingOperations() {
	        if(simpMessageSendingOperations == null) {
	        	simpMessageSendingOperations = SpringUtils.getBean(SimpMessageSendingOperations.class);
	        }
	        return simpMessageSendingOperations;
	    }*/

}
